package com.lxu.util;

import com.lxu.entity.WordEntity;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 仅仅复制
 */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
public class WordCopyOnly {
    /**
     * 表格字段填充+尾部扩展行
     */
    @Test
    public void fillComplexWord4Tail() throws Exception {
        Map<String, Object> textMap = generateTextMap();
        WordEntity wordEntity = new WordEntity();
        wordEntity.setTextMap(textMap);

        /**
         * 填充占位符
         */
        InputStream in = this.getClass().getResourceAsStream("/templates/表格既包含占位符又包含尾部扩展行-测试复制样式是否丢失.docx");
        XWPFDocument xwpfDocument = XWPFUtils.fillComplexWord(in, wordEntity);
        XWPFUtils.save("D:\\ComplexWord.docx", xwpfDocument);
    }

    private Map<String, Object> generateTextMap() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("industry", "房地产");
        map.put("product", "写字楼");
        return map;
    }
}
